package com.ttt.adbgui.function;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

/*
* 向表格填充列表数据
* */
@Component
@Slf4j
public class TableFill {

    // 两列
    public void tableFillData(JTable jTable) {

        String[][] tableData = new String[4][2];
        tableData[0][0] = "cmd /c adb devices";
        tableData[0][1] = "cmd /c adb shell ls /sdcard/";
        tableData[1][0] = "cmd /c adb";
        tableData[1][1] = "cmd /c ipconfig";
        tableData[2][0] = "cmd /c adb shell dumpsys window | findstr mCurrentFocus";
        tableData[2][1] = "cmd /c adb shell am monitor";
        tableData[3][0] = "cmd /c dir";
        tableData[3][1] = "cmd /c ping www.tencent.com";

        String[][] rowData = new String[tableData.length][tableData[0].length];

            for (int i = 0; i < rowData.length; i++) {
                for (int j = 1; j < rowData[i].length; j++) {
                    rowData[i][j] = tableData[i][j];
                }
                rowData[i][0] = tableData[i][0];
            }

            Object[] columnNames = {"A","B"};
            DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
                @Override
                public boolean isCellEditable(int row, int column) {
                    // TODO 自动生成的方法存根
                    return false;
                }
            };
            jTable.setModel(model);
    }

    // 单列
    public void tableDataFile(JTable jTable, ArrayList<String> strings) {

        String[][] rowData = new String[strings.size()][1];
        for (int i = 0; i < strings.size(); i++) {
            rowData[i][0] = strings.get(i);
        }

        Object[] columnNames = {"A"};
        DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
            @Override
            public boolean isCellEditable(int row, int column) {
                // TODO 自动生成的方法存根
                return false;
            }
        };
        jTable.setModel(model);
    }
}
